#include<iostream>
#include<vector>
#include<queue>

using namespace std;


struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};


class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        vector<vector<int>> answer;
        if (root == nullptr)
        {
            return answer;
        }

        int size = 0;
        queue<TreeNode*> h;
        if (root)
        {
            h.push(root);
            size = 1;
        }

        while (size)
        {
            vector<int>c;
            while (size--)
            {
                TreeNode* front = h.front();
                h.pop();
                c.push_back(front->val);
                if (front->left)
                {
                    h.push(front->left);
                }
                if (front->right)
                {
                    h.push(front->right);
                }
                size = h.size();
                answer.push_back(c);
            }
        }
        return answer;
    }
};



int main()
{
    return 0;
}